package com.arxan;


public class CalcSpeed implements Runnable {

    private boolean stop;
    private float passtime;
    private volatile int procItem = 0;
    private volatile float procsize = 0;
    
    /**
     * 线程主函数
     *
     * @param 
     * @return 
     */
    public void run() {
    	passtime = 0;
    	procItem = 0;
    	procsize = 0;
        while(!stop) {
            //System.out.print(Thread.currentThread().getName() + "");
            try {
				Thread.sleep(1000);
				passtime+=1.0;
				System.out.print("Calc Speed item:" + procItem + " passtime:" + passtime + " speed:" + procItem / passtime + " item/sec " + procsize / passtime + "bytes/sec\r");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
    }
    /**
     * 记录当前又处理了几条数据
     *
     * @param itemcount
     *          记录条数
     * @param datasize
     *          处理的字节数
     * @return 
     */
    public void processedItem(int itemcount,int datasize)
    {
    	procItem+=itemcount;
    	procsize += datasize;
    }

    public void stopThread() {
        this.stop = true;
    }

}
